package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.ProductAddDTO;
import org.jsola.hr.dto.ProductUpdateDTO;
import org.jsola.hr.entity.ProductDO;
import org.jsola.hr.query.ProductQuery;
import org.jsola.hr.service.IProductService;
import org.jsola.hr.vo.ProductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 产品
 *
 * @author zhr
 */
@Component
public class ProductTestHelper extends BaseTestHelper {
    
    @Autowired
    private IProductService productService;

    /**
     * 生成add测试数据
     * @return ProductAddDTO
     */
    public ProductAddDTO getProductAddDTO(){
        ProductAddDTO productAddDTO = new ProductAddDTO();
        productAddDTO.setProductTypeId(getRandomValue("varchar",32));
        productAddDTO.setProductName(getRandomValue("varchar",32));
        productAddDTO.setIsPrincipal(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        productAddDTO.setProductTag(getRandomValue("text",2147483647));
        productAddDTO.setProductIntroduce(getRandomValue("varchar",50));
        productAddDTO.setProductServiceCharge(getRandomValue("varchar",32));
        productAddDTO.setProductUrl(getRandomValue("text",2147483647));
        productAddDTO.setProductCover(getRandomValue("varchar",255));
        return productAddDTO;
    }


    /**
     * 生成update测试数据
     * @return ProductUpdateDTO
     */
    public ProductUpdateDTO getProductUpdateDTO(ProductVO productVO){
        return productService.selectDOById(productVO.getId(), SITE_ID).to(ProductUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return ProductQuery
     */
    public ProductQuery getProductQuery() {
        ProductQuery productQuery = new ProductQuery();
        List<ProductDO> productDOList = productService.list(new ProductDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(productDOList)) {
            ProductDO productDO = productDOList.get(0);
            productQuery = productDO.to(ProductQuery.class);
        }
        return productQuery;
    }

    /**
     * 保存示例
     * @return ProductVO
     */
    public ProductVO saveProductExample(){
        ProductAddDTO addDTO = this.getProductAddDTO();
        ProductVO productVO = productService.save(addDTO,buildTokenUser());
        return productVO;
    }


}

